#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sqlite3
import time

class Statistics:

    def get_teachers_establishment_year(self,year,estab,boolList):

        conn = sqlite3.connect('../Rebides.db')
        c = conn.cursor()
        c.execute('''SELECT teacher_name  FROM teachers_information WHERE year = '{0}' AND establishment = '{1}' '''.format(year, estab))
        tmp = c. fetchall()
        conn.close()

        nr_teachers_estab_year = []

        for l in range (len(tmp)):
            nr_teachers_estab_year.append(tmp[l][0].encode('utf-8'))
            pass
        
            
        if(boolList==False):
            return len(nr_teachers_estab_year)

        else:
            return nr_teachers_estab_year
    
        pass




    def get_teachers_cat_estab_year(self,year,estab,cat,boolList):

        conn = sqlite3.connect('../Rebides.db')
        c = conn.cursor()
        c.execute('''SELECT teacher_name  FROM teachers_information WHERE year = '{0}' AND establishment = '{1}' AND category = '{2}' '''.format(year, estab, cat))
        tmp = c. fetchall()
        conn.close()

        nr_teachers_cat_estab_year=[]
        
        for l in range (len(tmp)):
            nr_teachers_cat_estab_year.append(tmp[l][0].encode('utf-8'))
            pass

        if(boolList==False):
            return len(nr_teachers_cat_estab_year)

        else:
            return nr_teachers_cat_estab_year

        pass
    


    def get_teachers_deg_estab_year(self,year,estab,deg,boolList):

        conn = sqlite3.connect('../Rebides.db')
        c = conn.cursor()
        c.execute('''SELECT teacher_name  FROM teachers_information WHERE year = '{0}' AND establishment = '{1}' AND degree = '{2}' '''.format(year, estab, deg))
        tmp = c. fetchall()
        conn.close()


        nr_teachers_deg_estab_year=[]
        
        for l in range (len(tmp)):
            nr_teachers_deg_estab_year.append(tmp[l][0].encode('utf-8'))
            pass

        if(boolList==False):
            return len(nr_teachers_deg_estab_year)

        else:
            return nr_teachers_deg_estab_year

        pass



    def get_information(self, data):

        conn = sqlite3.connect('../Rebides.db')
        c = conn.cursor()
        for x in range(0,11):
            year=2000+x
            #print year
            c.execute('''SELECT {0} FROM teachers_information WHERE year = year '''.format(data)) 
            tmp = c. fetchall()
            pass
        conn.close()

        tempList= []
        for l in range (len(tmp)):
            tempList.append(tmp[l][0].encode('utf-8'))
            pass
        
        tempList = set(tempList)
        informationList = list(tempList)
        informationList.sort()

        if (data == "degree"):
            newDegreesList =[]
            newDegreesList=(filter(lambda (x): x.startswith('Do'), informationList))
            newDegreesList.extend(filter(lambda (x): x.startswith('L'), informationList))
            newDegreesList.extend(filter(lambda (x): x.startswith('M'), informationList))
            return newDegreesList
        
        else:
            return informationList

    pass

